package com.gsnd.briuppts.Result;

/**
 * 统一Controller中RESTFul风格接口返回的结果
 */
public class Response<T> {
    private Integer code;
    private String status;
    private String message;
    private T data; // 泛型 =》 类型参数化

    public Response() {
    }

    public Response(T data) {
        this.code = 200;
        this.status = "ok";
        this.message = "成功";
        this.data = data;
    }

    public Response(Integer code, String status, String message) {
        this.code = code;
        this.status = status;
        this.message = message;
    }

    public static <T> Response<T> success(T data) {
        return new Response(data);
    }

    public static <String> Response<String> success() {
        return new Response(com.gsnd.briuppts.Result.ResponseCode.SUCCESS);
    }

    public static Response error(ResponseCode responseCode, String message) {
        return new Response(responseCode.getCode(), responseCode.getStatus(), message);
    }

    public T getData() {
        return this.data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public Integer getCode() {
        return this.code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getStatus() {
        return this.status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMessage() {
        return this.message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String toString() {
        return "Response{code=" + this.code + ", status='" + this.status + '\'' + ", message='" + this.message + '\'' + ", data=" + this.data + '}';
    }
}